<h2>用户密码</h2>
<div id="centra-mine-form"
     data-topple="hsForm"
     data-save-url="centre/mine/save.act"
     data-load-url="centre/mine/info.act?ab=*&amp;rb=*"
     data--0="_fill_head:(hsFormFillPict)">
    <form action="" method="POST" enctype="multipart/form-data" autocomplete="off">
        <input type="hidden" name="id" data-fn/>
        <div style="height: 0; overflow: hidden;">
            <input type="text"     name="_u"/>
            <input type="password" name="_s"/>
        </div>
        <div class="form-group">
            <label class="control-label">原口令</label>
            <input type="password" name="passolde" class="form-control" required="required"/>
        </div>
        <div class="form-group">
            <label class="control-label">新口令</label>
            <input type="password" name="password" class="form-control" required="required" data-relate="passcode"/>
        </div>
        <div class="form-group">
            <input type="password" name="passcode" class="form-control" required="required" data-repeat="password" data-error="请重复输入口令" placeholder="请重复输入口令"/>
        </div>
        <div class="form-group form-control-static" style="padding-top: 0;">
            <a href="javascript:;" class="new-password">生成密码</a>
        </div>
        <div>
            <button type="submit" class="commit btn btn-primary">提交</button>
            <button type="button" class="cancel btn btn-link"   >取消</button>
        </div>
    </form>
</div>
<script type="text/javascript">
    (function($) {
        var context = H$("#centra-mima-form");

        context.on("click", ".new-password", function() {
            newPassword(32);
        });
        function newPassword(l) {
            var pw = getPassword(l);
            $.hsMask({
                mode : "warn",
                html : "请务必记住新的密码, 提交后将以不可逆加密的形式进行存储."
            }, {
                label: "更换",
                glass: "btn-default",
                click: function(ev) {
                    ev.preventDefault();
                    pw = getPassword(l);
                    $(this).closest(".modal").find(".code").text(pw);
                }
            }, {
                label: "拷贝",
                glass: "btn-default",
                click: function(ev) {
                    ev.preventDefault();
                    $(this).closest(".modal").find(".code").hsCopy();
                }
            }, {
                label: "确认",
                glass: "btn-primary",
                click: function() {
                    context.find("[name=password],[name=passcode]").val(pw);
                }
            }).find(".alert-title").html('新密码: <b class="code">'+ pw +'</b>');
        }
        function getPassword(l) {
            var cs = [
                ['A', 'B', 'C', 'D', 'E', 'F', 'G',
                 'H', 'I', 'G', 'K', 'M', 'N',
                 'P', 'Q', 'R', 'S', 'T',
                 'U', 'V', 'W', 'X', 'Y'],
                ['a', 'b', 'c', 'd', 'e', 'f', 'g',
                 'h', 'i', 'g', 'k', 'm', 'n',
                 'p', 'q', 'r', 's', 't',
                 'u', 'v', 'w', 'x', 'y'],
                ['3', '4', '5', '6', '7', '8', '9'],
                ['@', '#', '$', '%', '&']
            ];
            var ps = [];
            var hasNum = false; // 至少含有一个数字
            var hasSym = false; // 至少含有一个符号
            for(var i = 0; i < l; i ++) {
                var j = Math.floor(Math.random() * 100);
                var x = j % cs.length;
                if (x === 2 && !hasNum) {
                    hasNum = true;
                } else
                if (x === 3 && !hasSym) {
                    hasSym = true;
                }
                if (i === 6 && !hasNum) {
                    x = 2;
                } else
                if (i === 7 && !hasSym) {
                    x = 3;
                }
                var y = j % cs[x].length;
                ps.push (cs[x][y]);
            }
            return ps.join("");
        }
    })(jQuery);
</script>